#include "CustomizedMap.h"


using namespace std;

map<string, string> CustomizedMap::getMap() {
	return this->customMap;
}

string CustomizedMap::getAttribute(std::string key)throw (AttributeNotFoundException){
	map<string, string>::iterator ii;

	for(ii= this->customMap.begin(); ii!=this->customMap.end(); ++ii){	   
	   if ((*ii).first == key){
		   string value = (*ii).second;
	   return value;
	   }
	}
	throw AttributeNotFoundException("El atributo que desea buscar no fue encontrado");
}

int CustomizedMap::getAttributeQuantity(){
	return customMap.size();
}

bool CustomizedMap::isValidResolution(){
	return customMap.size()==1;
}

bool CustomizedMap::isValidScreenColor(){
	return customMap.size()==1;
}

bool CustomizedMap::isValidLineColor(){
	return customMap.size()==1;
}

bool CustomizedMap::isValidFigureColor(){
	return customMap.size()==1;
}


bool CustomizedMap::isValid(ObjectType elementType, std::string type){
	ObjectType objType = ObjectTypeUtils::getObjectTypeByString(type);
	switch(objType){
		case square:return isValidSquare();
		case segment: return isValidSegment();
		case rectangle: return isValidRectangle();
		case circle: return isValidCircle();
		case texture: return isValidTexture(elementType);
		case position: return isValidPosition();
		case begin: return isValidBegin();
		case end: return isValidEnd();
		case resolution: return isValidResolution();
		case screenColor: return isValidScreenColor();
		case lineColor: return isValidLineColor();
		case figureColor: return isValidFigureColor();
		default: return false;
	}
}

bool CustomizedMap::isValidSquare(){
	//Asumo que tiene los atributos id,lado por defecto
	int attributeCounter=2;
	if(customMap.find("colorLinea")!=customMap.end())attributeCounter++;
	if(customMap.find("colorFigura")!=customMap.end())attributeCounter++;
	if(customMap.find("textura")!=customMap.end())attributeCounter++;
	return (customMap.size()==attributeCounter);
}

//<inicio x="XXX" y="YYY"> tiene 2
bool CustomizedMap::isValidBegin(){
	return(customMap.size()==2);
}

bool CustomizedMap::isValidCircle(){
	//Asumo que tiene los atributos id,radio, por defecto
	int attributeCounter=2;
	if(customMap.find("colorLinea")!=customMap.end())attributeCounter++;
	if(customMap.find("colorFigura")!=customMap.end())attributeCounter++;
	if(customMap.find("textura")!=customMap.end())attributeCounter++;
	return (customMap.size()==attributeCounter);
}

//x,y
bool CustomizedMap::isValidEnd(){
	return(customMap.size()==2);
}

//x,y
bool CustomizedMap::isValidPosition(){
	return(customMap.size()==2);
}

bool CustomizedMap::isValidRectangle(){
	//Asumo que tiene los atributos id,base, altura por defecto
	int attributeCounter=3;
	if(customMap.find("colorLinea")!=customMap.end())attributeCounter++;
	if(customMap.find("colorFigura")!=customMap.end())attributeCounter++;
	if(customMap.find("textura")!=customMap.end())attributeCounter++;
	return (customMap.size()==attributeCounter);
}

//id
bool CustomizedMap::isValidSegment(){
	int attributeCounter=1;
	//opcional solo color de linea
	if(customMap.find("colorLinea")!=customMap.end())attributeCounter++;
	return (customMap.size()==attributeCounter);
}

//is, path
bool CustomizedMap::isValidTexture(ObjectType type){
	if(ObjectTypeUtils::isGeneralTag(type))
		return(customMap.size()==1);
	else return(customMap.size()==2);
}
